#ifndef _TCP_CLIENT_H_
#define _TCP_CLIENT_H_

#include <boost/asio.hpp>
#include <boost/cstdint.hpp>
#include <boost/bind.hpp>
#include <string>
#include <queue>

namespace auroral { namespace net {

using namespace boost;
using namespace boost::asio::ip;

// ************************************ class TcpClient ***************************************
class TcpClient
{
public:
	TcpClient(boost::asio::io_service& io_service, const std::string& server, int16_t port);

	virtual ~TcpClient();
	virtual bool active();
	virtual void async_write(const std::string &message);

protected:

	// process the data restored in @response_
	virtual void process_read() = 0;

	virtual void push_write_queue(const std::string message);

	virtual void handle_read(const boost::system::error_code& err);

	virtual void handle_write(const boost::system::error_code& err/*error*/,
		size_t /*bytes_transferred*/);

	virtual void handle_resolve(const boost::system::error_code& err,
		tcp::resolver::iterator endpoint_iterator);

	void handle_connect(const boost::system::error_code& err,
		tcp::resolver::iterator endpoint_iterator);

	tcp::socket socket_;
	std::queue<std::string> messages_;
	boost::asio::streambuf response_;
	boost::asio::io_service::strand strand_;
	tcp::resolver resolver_;
	std::string server_;
	int16_t port_;
	bool writting;
};

} }; // namespace auroral::net

#endif // _TCP_CLIENT_H_